package com.pen.changgou.goods.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;
import java.util.Map;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pen.changgou.goods.entity.Pref;
import com.pen.changgou.goods.service.PrefService;
import com.pen.changgou.common.core.utils.R;

import java.util.Arrays;

/**
 * 
 *
 * @author yaodao
 * @email lfy@pen.changgou.com
 * @date 2020-11-29 17:35:47
 */
@Api(tags = " 管理")
@RestController
@RequestMapping("/pref")
public class PrefController {
    @Autowired
    private PrefService prefService;

    /**
     * 通过ID查询菜单的详细信息
     * @param id 菜单ID
     * @return 菜单详细信息
     */
    @GetMapping("/{id}")
    public R getById(@PathVariable Long id) {
        return R.ok(prefService.getById(id));
    }

    /**
     * 列表
     */
    @ApiOperation("分页查询(排序)")
    @GetMapping("/page")
    public R<Page> pge( Page page,Pref pref) {
        return R.ok( prefService.page(page,Wrappers.query(pref)));

    }

    @ApiOperation("分页查询(排序)")
    @GetMapping("/list")
    public R<List<Pref>> list(Map<String,Object> param) {
        return R.ok(prefService.list(new QueryWrapper<>()));

    }
    /**
     * 信息
     */
    @ApiOperation("详情查询")
    @GetMapping("/info/{id}")

    public R<Pref> info(@PathVariable("id") Long id){
		Pref pref = prefService.getById(id);

        return R.ok(pref);
    }

    /**
     * 保存
     */
    @ApiOperation("保存")
    @PostMapping("/save")

    public R<Object> save(@RequestBody Pref pref){
		prefService.save(pref);

        return R.ok(null);
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @PostMapping("/update")
    public R<Object> update(@RequestBody Pref
        pref){
		prefService.updateById(pref);

        return R.ok(null);
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @PostMapping("/delete")
    public R<Object> delete(@RequestBody Long[] ids){
		prefService.removeByIds(Arrays.asList(ids));

        return R.ok(null);
    }

}
